
#ifndef SOCKETSOPS_HPP
#define SOCKETSOPS_HPP

#include <arpa/inet.h>

namespace tulun
{
    namespace Sockets
    {
        void fromIpPort(const char *ip, uint16_t port, struct sockaddr_in *addr);
        void toIpPort(char *buff, size_t len, const struct sockaddr_in &addr);
        void toIp(char *buff, size_t len, const struct sockaddr_in &addr);
        void setNonBlock(int sockfd);
        void close(int sockfd);
        void bindOrDie(int sockfd, const struct sockaddr_in &addr);
        void listenOrDie(int sockfd);
        int accept(int sockfd, struct sockaddr_in *addr);
        void shutdownWrite(int sockfd);
        int createNonblockingOrDie();
        int createBlockingOrDie();
        int Connect(int sockfd, const struct sockaddr_in &addr);
        struct sockaddr_in getLocalAddr(int sockfd);
        struct sockaddr_in getPeerAddr(int sockfd);
        bool isSelfConnect(int sockfd);
        int getSocketError(int sockfd);
        ssize_t read(int sockfd, void *buf, size_t count);
        ssize_t readv(int sockfd, const struct iovec *iov, int iovcnt);
        ssize_t write(int sockfd, const void *buf, size_t count);
    }
} // namespace tulun

#endif